﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example13.aspx.cs" Inherits="Chapter30.Example13" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 30-13 使用键盘事件</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <style title="cor styles">
        p {
            background: gray;
            color: white;
            padding: 10px;
            margin: 5px;
            border: thin solid black;
        }
    </style>
</head>
<body>
    <form>
        <p>
            <label for="fave">
                Fruit:
                <input autofocus="autofocus" id="fave" name="fave" />
            </label>
        </p>
        <p>
            <label for="name">
                Name:
                <input autofocus="autofocus" id="name" name="name" />
            </label>
        </p>
        <button type="submit">Submit Vote</button>
        <button type="reset">Reset</button>
    </form>
    <span id="message"></span>
    <script>
        var inputElems = document.getElementsByTagName("input");
        for (var i = 0; i < inputElems.length; i++) {
            inputElems[i].onkeyup = handleKeyboardEvent;
        }

        function handleKeyboardEvent(e) {
            document.getElementById("message").innerHTML = "key pressed: " + e.keyCode + " Char: " + String.fromCharCode(e.keyCode);
        }
    </script>
</body>
</html>
